#include<bits/stdc++.h>

using namespace std;
const int N = 1e5 + 10;

int get_long(int x1, int y1, int x2, int y2)
{
	int dx = x1 - x2;
	int dy = y1 - y2;
	return dx * dx + dy * dy;
}
struct node
{
	int l, r;
}a[N];

bool cmp(node& a, node& b)
{
	return a.l > b.l;
}
int main()
{
	int n, x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2 >> n;
	for(int i = 1; i <= n; i++)
	{
		int x, y; cin >> x >> y;
		a[i].l = get_long(x, y, x1, y1);
		a[i].r = get_long(x, y, x2, y2);
	}
	sort(a + 1, a + 1 + n, cmp);
	
	int ret = a[1].l;
	int r2 = 0;
	
	for(int i = 2; i <= n + 1; i++)
	{
		int r1 = a[i].l;
		r2 = max(r2, a[i - 1].r);
		
		ret = min(ret, r1 + r2);
	}
	cout << ret << endl;
	return 0;
} 
